package com.swe727.spring2011.constraint1.node;

import java.io.Serializable;
import com.swe727.spring2011.constraint1.coordinate.Coordinate;
import com.swe727.spring2011.constraint1.message.Message;
import com.swe727.spring2011.constraint1.node.*;
import com.swe727.spring2011.constraint1.observation.ObservationType;


/**
 * A Node is the representation of an observer registered with the server.
 * @author Fernando Boccanera
 *
 */
public class Node implements Serializable {

	/**
	 * Auto-generated serial ID 
	 */
	private static final long serialVersionUID = 389635372857091500L;
	
	/**
	 * The nodeId 
	 */
	private final String NODE_ID;
	/**
	 * The IP address of the node's RMI server
	 */
	private final String IP_ADDRESS;
	/**
	 * The port of the node's RMI server
	 */
	private final int PORT;
	/**
	 * Create a new Node.
	 * @param nodeId Id of the Node in the node's RMI server
	 * @param ipAddress ip address of the node's RMI server
	 * @param port port of the node's RMI server
	 */
	public Node(String nodeId, String ipAddress, int port) {
		NODE_ID = nodeId;
		IP_ADDRESS = ipAddress;
		PORT = port;
	}

	/**
	 * Getter methods
	 */
	public String getNodeId() {
		return NODE_ID;
	}

	public String getIPAddress() {
		return IP_ADDRESS;
	}

	public int getPort() {
		return PORT;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((IP_ADDRESS == null) ? 0 : IP_ADDRESS.hashCode());
		result = prime * result + ((NODE_ID == null) ? 0 : NODE_ID.hashCode());
		result = prime * result + PORT;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Node other = (Node) obj;
		if (IP_ADDRESS == null) {
			if (other.IP_ADDRESS != null)
				return false;
		} else if (!IP_ADDRESS.equals(other.IP_ADDRESS))
			return false;
		if (NODE_ID == null) {
			if (other.NODE_ID != null)
				return false;
		} else if (!NODE_ID.equals(other.NODE_ID))
			return false;
		if (PORT != other.PORT)
			return false;
		return true;
	}
}
